#include "test.h"

#include <stdio.h>              /* printf */
#include <stdarg.h>             /* va_start */
#include <errno.h>              /* errno */
#include <string.h>             /* strerror */

void __fl_pt_times__(clock_t real, struct tms *tmsstart, struct tms *tmsend)
{
  static long clk = 0;

  if (clk == 0)
    if ((clk = sysconf(_SC_CLK_TCK)) < 0)
      FL_SYSTEM_ERROR("sysconf error");

  fprintf(stderr, "real: %f, ", real / (double)clk);
  fprintf(stderr, "user: %f, ", (tmsend->tms_utime - tmsstart->tms_utime) / (double)clk);
  fprintf(stderr, "sys: %f\n", (tmsend->tms_stime - tmsstart->tms_stime) / (double)clk);
}

void __fl_err_doit__(const char *file, unsigned int line, const char *fmt, ...)
{
  va_list ap; va_start(ap, fmt);
  int errno_save = errno;

  if (fmt) {
    fprintf(stderr, "%s %d - %s -> ", file, line, (char*)strerror(errno_save));
    vfprintf(stderr, fmt, ap);
    fputs("\n", stderr);
  } else
    fprintf(stderr, "%s %d - %s\n", file, line, (char*)strerror(errno_save));

  va_end(ap);
}
